/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.seedlistgenerator;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Jonas ExecuteProgram contains the main class.
 */
public class ExecuteProgram {

    private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(ExecuteProgram.class);
    private Map<Integer, String[]> projects;

    /*
     * Projects hashmap contains the projectID's and the corresponding runnumbers.
     * The hashmap is filled when ExecuteProgram is called for.
     */
    public ExecuteProgram() {

        projects = new HashMap<Integer, String[]>();

        String[] runs_1 = {"8740"}; //, "8741", "8742", "8743", "8744", "8745", "8746", "8747", "8748", "8749", "8750", "8751", "8752", "8753", "8754", "8755", "8756", "8757", "8758", "8759"};
        projects.put(1918, runs_1);
//        String[] runs_2 = {"9017", "9018", "9019", "9020", "9021", "9022", "9023", "9024", "9025", "9026", "9027", "9028", "9029", "9030", "9031", "9032", "9033", "9034", "9035", "9036"};
//        projects.put(1941, runs_2);
//        String[] runs_3 = {"9040", "9041", "9042", "9043", "9044", "9045", "9046", "9047", "9048", "9049", "9050", "9051", "9052", "9053", "9054", "9055", "9056", "9057", "9058", "9059"};
//        projects.put(1942, runs_3);
    }

    public static void main(String[] args) {
        // Fills the "projects" hashmap with the right projectID's and runnumbers
        ExecuteProgram executeProgram = new ExecuteProgram();
        executeProgram.doMain();
    }

    public void doMain() {

        DataProvider dataProvider = new DataProvider();
        XMLBuilder xMLBuilder = new XMLBuilder();

        for (int projectID : projects.keySet()) {
            String[] runs = projects.get(projectID);
            for (int i = 0; i < runs.length; i++) {
                System.out.println("");
                LOGGER.info("Processing project " + projectID + " run " + runs[i]);

                // Execute the ms_lims query
                List<MS2Identifications> identificationsList = dataProvider.querySpectrumVariables(projectID, runs[i]);

                /*
                 * Build and save the seedlist as an xml-file in a specified folder.
                 * Building and saving happens in the XMLBuilder class.
                 */
                File xmlFile = new File("C:\\Test\\XMLFiles\\" + projectID + "\\" + runs[i] + ".featureXML");
                xMLBuilder.buildSeedList(identificationsList, xmlFile);

            }
        }
    }
}
